﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WrapperCode = DCT.CodeBox.Log4netWrapper.Codes;
using ExtCode = DCT.CodeBox.Log4netWrapper.LightLogExtension.Codes;
using System.Dynamic;

namespace DCT.CodeBox.Log4netWrapper.LightLogExtension
{
    class Program
    {
        /// <summary>
        /// 例子
        /// </summary>
        class Log4netExtSample1
        {
            private static DCT.CodeBox.LightLog.Codes.ILog log = null;

            static Log4netExtSample1()
            {
                //先初始化Log4net
                WrapperCode.Log4netWrapper wrapper = new WrapperCode.Log4netWrapper();
                wrapper.SetInitialConfig(WrapperCode.Log4netWrapper.InitialConfigFromFile("logConfig.xml"));
                wrapper.DefaultLoggerName = "myLogger";

                //再初始化自定义的ILog
                log = new ExtCode.LightLog4Net();
                log.LoadConfig(wrapper.GetLogger());
            }

            public static DCT.CodeBox.LightLog.Codes.ILog Log
            {
                get
                {
                    return log;
                }
            }
        }

        static void Main(string[] args)
        {
            //一般类型
            Log4netExtSample1.Log.I("test", 1);
            Log4netExtSample1.Log.D("test", 0.1);
            Log4netExtSample1.Log.W("test", true);
            Log4netExtSample1.Log.E("test", "这是一个字符串");

            //实体Object
            Log4netExtSample1.Log.F("test_object", new
            {
                Name = "Peter",
                Age = 29
            });

            //Dictionary
            Log4netExtSample1.Log.Log(LightLog.Codes.LogLevel.Info, "test_dict", (new Dictionary<string, object>()
            { 
                {"Task1",    "需求分析"},
                {"Task2",    "概要设计"},
                {"Task3",    "编码测试"}
            }));

            //expandoObject
            dynamic obj = new ExpandoObject();
            obj.Name = "Anna";
            obj.Position = "Project Manager";
            Log4netExtSample1.Log.Log(LightLog.Codes.LogLevel.Error, "test_ExpandoObject", obj);

            Console.WriteLine("done...");
        }
    }
}
